<template>
    <div class="e-form">
        <BillTop title="租赁计划变更新增" @cancel="handleClose"></BillTop>
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="form" label-width="200px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="计划编号：">
                            <span>{{ formData.billNo }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="变更日期：">
                            <span>{{ formData.billDate }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="币种：">
                            <span>{{ formData.currency }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="原金额（元）：">
                            <span>{{ formData.totalCost }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="变更后金额（元）：">
                            <span>{{ formData.changeTotalCost }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="机构：">
                            <span>{{ formData.orgName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="状态：">
                            <span>{{ statusLable(formData.state) }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="租赁类型：">
                            <span>{{formData.leaseType ? leaseTypeList[formData.leaseType].label :''}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="变更期数：">
                            <span>{{formData.number}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="本位币：">
                            <span>{{ formData.baseCurName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="传输财务共享：">
                            <span>{{ formData.share }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item  label="租赁说明：">
                            <el-input type="textarea" v-model="formData.remarks" placeholder="请输入内容"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="人民币汇率：">
                            <span>{{formData.rmbRate}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                v-debounce
                >保存</el-button
            >
            <el-button size="small" @click="handleClose"  v-debounce>取消</el-button>
        </div>
    </div>
</template>

<script>
import { mapState } from 'vuex'
import '@/utils/jquery.scrollTo.min'
import request from '@/api/equip/equipPlan.js'
// import { formatDate } from '@/utils/common.js'
export default {
    data () {
        return {
            selectEquipVisible: false,
            formData: {
                'share': '',
                'auditCost': 0,
                'auditTime': '',
                'auditor': '',
                'auditorId': '',
                'baseCurId': '',
                'baseCurName': '',
                'baseCurRate': 0,
                'baseCurTotalCost': 0,
                'billDate': '',
                'billId': '',
                'billNo': '',
                'changeBillId': '',
                'changeBillNo': '',
                'changeState': null,
                'changeTotalCost': 0,
                'configurationPlanId': '',
                'configurationPlanNo': '',
                'currency': '',
                'currencyId': '',
                'esaId': '',
                'founderId': '',
                'founderName': '',
                'isExcss': 0,
                'isTemporaryLease': '',
                'leaseType': '',
                'modifier': '',
                'modifierId': '',
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'number': 0,
                'orgId': '',
                'orgName': '',
                'recorder': '',
                'recorderId': '',
                'remarks': '',
                'rmbId': '',
                'rmbName': '',
                'rmbRate': 0,
                'rmbSumTotalCost': 0,
                'settleAmount': 0,
                'source': '',
                'state': 0,
                'totalCost': 0,
                'version': 0,
                'workId': ''
            },
            billid: this.$route.query.billid,
        }
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm, //币种
            leaseTypeList: state => state.equip.equipData.leaseTypeList, //租赁类型
        }),
        //状态
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>+x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
    },
    components: {
    },
    created () {
        this.userId = localStorage.getItem('userId')
        this.getInfo()
    },
    mounted () {

    },
    methods: {
        getInfo () { //默认获取数据
            const date = new Date()
            const params = {
                planId: this.billid,
                userId: this.userId
            }
            request.getInitLeaseBaseInfo(params).then(res=>{
                res.state = 0
                this.formData = res
                this.formData.billDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                this.formData.changeBillId = this.billid
            })
        },
        //保存
        preserve () {
            request.baseLeaseChangeAdd(this.formData).then(res=>{
                this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                    this.$router.push({
                        path: '/leasePlanChangeEdit',
                        query: {
                            billid: res,
                            name: 'planDetail'
                        }
                    })
                },
                null,
                this.handleClose
                )
            })
        },
        handleHistory () {
            this.$router.push({
                path: '/leasePlanShow',
                query: {
                    billid: this.billid,
                    name: 'changeHistory'
                }
            })
        },
        //取消
        handleClose () {
            this.$router.replace('/leasePlanList')
        },

    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.form {
    margin-top: 10px;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
